class Solution
{
public:
    vector<int> sortArrayByParity(vector<int> &nums)
    {
        int n = nums.size();
        vector<int> result(n);
        int fore = 0;
        int back = n - 1;
        for (int num : nums)
        {
            if (num & 1)
            {
                result[back] = num;
                --back;
            }
            else
            {
                result[fore] = num;
                ++fore;
            }
        }
        return result;
    }
};